/*
 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

const SEVERITY = {
  SUGGEST: 1,
  MINOR: 2,
};

export const tsRules = [
  {
    checker: "WebNotSetMixedModeNone",
    severity: SEVERITY.MINOR,
    description: "建议Web组件的mixedMode属性配置成None",
    category: "ARKTS",
  },
  {
    checker: "WebUnSetFileAccess",
    severity: SEVERITY.MINOR,
    description: "建议Web组件配置成fileAccess(false)或者配置成fileAccess(true)",
    category: "ARKTS",
  },
  {
    checker: "OnConnectReturnNull",
    severity: SEVERITY.MINOR,
    description: "在ServiceExtensionAbility的onConnect的回调函数中不要返回null",
    category: "ARKTS",
  },
  {
    checker: "WebUnSetGeolocationAccess",
    severity: SEVERITY.MINOR,
    description:
      "Web组件如果无地理位置使用场景，需要显示配置成geolocationAccess(false)",
    category: "ARKTS",
  },
  {
    checker: "PrintPrivateData",
    severity: SEVERITY.MINOR,
    description: "日志打印未匿名化的敏感信息",
    category: "ARKTS",
  },
  {
    checker: "BundleRpc",
    severity: SEVERITY.MINOR,
    description: "请使用getCallingUid等方式校验调用者身份",
    category: "ARKTS",
  },
  {
    checker: "FileNotClose",
    severity: SEVERITY.MINOR,
    description: "文件流没有关闭或者没有在finally中关闭",
    category: "ARKTS",
  },
  {
    checker: "NoPersonalInfoInComment",
    severity: SEVERITY.MINOR,
    description: "正式发布的代码及注释内容不应该包括开发者个人信息",
    category: "ARKTS",
  },
  {
    checker: "HardCode",
    severity: SEVERITY.MINOR,
    description: "存在密钥硬编码",
    category: "ARKTS",
  },
  {
    checker: "PrintWorkKey",
    severity: SEVERITY.MINOR,
    description: "禁止明文打印工作密钥，需要对密钥进行匿名化处理",
    category: "ARKTS",
  },
  {
    checker: "PrintPrivateKey",
    severity: SEVERITY.MINOR,
    description: "禁止明文打印私钥，需要对密钥进行匿名化处理",
    category: "ARKTS",
  },
  {
    checker: "OnConnectCheckUid",
    severity: SEVERITY.MINOR,
    description:
      "请将对调用者身份的校验放在实际调用服务接口时的回调函数onRemoteMessageRequest",
    category: "ARKTS",
  },
  {
    checker: "AddAccessClassAttribute",
    severity: SEVERITY.SUGGEST,
    description: "建议添加类属性的可访问修饰符",
    category: "ARKTS",
  },
  {
    checker: "NotUseESObject",
    severity: SEVERITY.SUGGEST,
    description: "避免使用ESObject",
    category: "ARKTS",
  },
  {
    checker: "UseUpperCamelCase",
    severity: SEVERITY.SUGGEST,
    description: "类名、枚举名采用UpperCameCase风格",
    category: "ARKTS",
  },
  {
    checker: "NameSpaceUseLowerCamelCase",
    severity: SEVERITY.SUGGEST,
    description: "命名空间名采用LowerCameCase风格",
    category: "ARKTS",
  },
  {
    checker: "CheckNaNUseIsNaN",
    severity: SEVERITY.MINOR,
    description: "判断变量是否为NaN必须使用isNaN()方法",
    category: "ARKTS",
  },
  {
    checker: "AvoidNegBoolVariableName",
    severity: SEVERITY.SUGGEST,
    description:
      "避免使用否定的布尔变量名，布尔型的局部变量或方法需加上表达是非意义的前缀",
    category: "ARKTS",
  },
  {
    checker: "UseLiteralStyleDeclaration",
    severity: SEVERITY.MINOR,
    description: "使用字面量风格的声明",
    category: "ARKTS",
  },
  {
    checker: "NoSensitiveDataInLocalSessionStorage",
    severity: SEVERITY.MINOR,
    description: "禁止在localStorage和sessionStorage中存储敏感数据",
    category: "ARKTS",
  },
  {
    checker: "NameUseLowerCamelCase",
    severity: SEVERITY.SUGGEST,
    description: "变量名、方法名、参数名采用lowerCamelCase风格",
    category: "ARKTS",
  },
  {
    checker: "NotUseReturnInFinallyBlock",
    severity: SEVERITY.MINOR,
    description:
      "不要使用return、break、continue或抛出异常使finally块非正常结束",
    category: "ARKTS",
  },
  {
    checker: "MultipleVarAndAssignNotInOneLine",
    severity: SEVERITY.MINOR,
    description: "多个变量定义和赋值语句不允许写在一行",
    category: "ARKTS",
  },
  {
    checker: "NotOverFourKeyLine",
    severity: SEVERITY.SUGGEST,
    description: "对象自变量超过4个，需要都换行",
    category: "ARKTS",
  },
  {
    checker: "NotOmitZeroInFloatNumber",
    severity: SEVERITY.MINOR,
    description: "禁止省略浮点数小数前后的0",
    category: "ARKTS",
  },
  {
    checker: "NotOverLineWidth",
    severity: SEVERITY.SUGGEST,
    description: "行宽不超过120个字符",
    category: "ARKTS",
  },
  {
    checker: "StringUseSingleQuotation",
    severity: SEVERITY.SUGGEST,
    description: "建议字符串使用单引号",
    category: "ARKTS",
  },
  {
    checker: "OperatorAtEndLine",
    severity: SEVERITY.SUGGEST,
    description: "表达式换行必须保持一致性，运算符放在行末",
    category: "ARKTS",
  },
  {
    checker: "PutElseCatchOnSameLine",
    severity: SEVERITY.SUGGEST,
    description: "把else/catch 放在 if/try代码块关闭括号的同一行",
    category: "ARKTS",
  },
  {
    checker: "UseTArrayType",
    severity: SEVERITY.SUGGEST,
    description: "使用T[]表示数组类型",
    category: "ARKTS",
  },
  {
    checker: "JsonParseShouldInTryCatch",
    severity: SEVERITY.MINOR,
    description: "使用JSON.parse()进行解析时，需要使用try catch进行异常捕获",
    category: "ARKTS",
  },
  {
    checker: "JsonStringifyShouldInTryCatch",
    severity: SEVERITY.MINOR,
    description:
      "使用JSON.stringify()进行解析时，需要使用try catch进行异常捕获",
    category: "ARKTS",
  },
  {
    checker: "NoSensitiveDataInWebSqlOrIndexed",
    severity: SEVERITY.MINOR,
    description: "禁止在Web SQL database和Indexed database数据库中存储敏感数据",
    category: "ARKTS",
  },
  {
    checker: "BraceAndStateOnSameLine",
    severity: SEVERITY.SUGGEST,
    description: "大括号{和语句在同一行",
    category: "ARKTS",
  },
  {
    checker: "IfAndForStatusUseBrace",
    severity: SEVERITY.SUGGEST,
    description: "条件语句和循环语句的实现必须使用大括号",
    category: "ARKTS",
  },
  {
    checker: "TraversalArrUseArrObjectMethods",
    severity: SEVERITY.SUGGEST,
    description: "数组遍历优先使用Array对象方法",
    category: "ARKTS",
  },
  {
    checker: "UrlRegCheck",
    severity: SEVERITY.MINOR,
    description: "正则校验url是否为http/https开头时，正则应以^http开头",
    category: "ARKTS",
  },
  {
    checker: "NoPublicUrl",
    severity: SEVERITY.MINOR,
    description: "禁止代码中包含公网地址",
    category: "ARKTS",
  },
  {
    checker: "NotInitInControlExpression",
    severity: SEVERITY.MINOR,
    description: "不要在控制性条件表达式中执行赋值操作",
    category: "ARKTS",
  },
  {
    checker: "SwitchIntendOneLevel",
    severity: SEVERITY.SUGGEST,
    description: "switch语句的case和default须缩进一层",
    category: "ARKTS",
  },
  {
    checker: "NotUseUnnecessarySpaces",
    severity: SEVERITY.SUGGEST,
    description: "空格应该突出关键字和重要信息，避免不必要的空格",
    category: "ARKTS",
  },
  {
    checker: "DeleteUnusedCode",
    severity: SEVERITY.MINOR,
    description: "不用的代码直接删除，不要注释掉",
    category: "ARKTS",
  },
  {
    checker: "NoBool",
    severity: SEVERITY.MINOR,
    description: "参数类型标注不支持bool关键字",
    category: "ARKTS",
  },
  {
    checker: "NoAnyOrUnknown",
    severity: SEVERITY.MINOR,
    description: "ArkTS不支持any和unknown类型，需显示指定具体类型。",
    category: "ARKTS",
  },
  {
    checker: "NoTsIgnore",
    severity: SEVERITY.MINOR,
    description: "不支持使用ts-ignore屏蔽代码检查",
    category: "ARKTS",
  },
  {
    checker: "DefineEnumValueVisible",
    severity: SEVERITY.MINOR,
    description: "应该显示定义枚举成员值",
    category: "ARKTS",
  },
  {
    checker: "EnumKeyNotIrregular",
    severity: SEVERITY.MINOR,
    description: "枚举key值没用下划线分割或者key名称不规范",
    category: "ARKTS",
  },
];
